package com.longrise.co.base;

import android.os.Bundle;
import android.support.annotation.Nullable;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.RelativeLayout;
import android.widget.TextView;

import com.longrise.co.R;
import com.ly.common.base.BaseFragment;
import com.ly.common.base.BaseModel;
import com.ly.common.base.BasePresenter;
import com.ly.common.baserx.RxManager;
import com.ly.common.commonutils.StringUtils;
import com.ly.common.commonutils.TUtil;

import butterknife.ButterKnife;

/**
 * Created by luoyang on 2017-6-22.
 */

public abstract class BaseBackFragment<T extends BasePresenter, E extends BaseModel> extends BaseFragment implements View.OnClickListener {

    private TextView mTitle;

    public T mPresenter;
    public E mModel;

    @Nullable
    @Override
    public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
        if (rootView == null)
            rootView = inflater.inflate(getLayoutResource(), container, false);
        RelativeLayout backRl = (RelativeLayout) rootView.findViewById(R.id.head_back);
        mTitle = (TextView)rootView.findViewById(R.id.head_title) ;
        if(backRl != null) {
            backRl.setOnClickListener(this);
        }

        mRxManager=new RxManager();
        ButterKnife.bind(this, rootView);
        mPresenter = TUtil.getT(this, 0);
        mModel= TUtil.getT(this,1);
        if(mPresenter!=null){
            mPresenter.mContext= _mActivity;
        }
        initPresenter();
        initView();
        return rootView;
    }

    @Override
    public void onClick(View v) {
        _mActivity.onBackPressed();
    }

    public void setTitle(String title) {
        if(!StringUtils.isEmpty(title) && mTitle != null) {
            mTitle.setText(title);
        }
    }
}
